#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_betafreq2.info <<'%EOF%'
   cc_rsp_betafreq2
   ----------------
   Molecule:         HF in C2
   Wave Function:    CCS, CCSD / 6-31G**
   Test Purpose:     First hyperpolarizabilities
                     - ZZZ, XXZ, XZX, ZXX components
                     - Static and for two non-zero frequencies
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_betafreq2.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    1  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_betafreq2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.TITLE
  first hyperpolarizability for the HF molecule
  for CCS and CCSD wavefunctions compute:
  - ZZZ, XXZ, XZX, ZXX components
  - static and for two non-zero frequencies
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CCSD
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
*CCQR
.OPERATOR
ZDIPLEN ZDIPLEN ZDIPLEN
XDIPLEN XDIPLEN ZDIPLEN
XDIPLEN ZDIPLEN XDIPLEN
XDIPLEN XDIPLEN ZDIPLEN
.STATIC
.SHGFRE
  2
0.04282270  0.06562487
.ORFREQ
  2
0.04282270  0.06562487
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_betafreq2.check
cat >>cc_rsp_betafreq2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Total SCF   energy:                  \-100.008919(8|9)." $log | wc -l`
CRIT2=`$GREP "Total MP2   energy:                  \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy:                  \-100.1977909." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=7
ERROR[1]="ENERGIES NOT CORRECT"


# freq.-dep. CCS hyperpolarizabilities
CRIT1=`$GREP  "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000      16.5732" $log | wc -l`
CRIT2=`$GREP  "                  ...0856                      ..0428                      ..0428      17.0182" $log | wc -l`
CRIT3=`$GREP  "                  ...1312                      ..0656                      ..0656      17.6491" $log | wc -l`
CRIT4=`$GREP  "                  (\-0| \-| 0|  )\.0000                      ..0428                     ...0428      16.7195" $log | wc -l`
CRIT5=`$GREP  "                  (\-0| \-| 0|  )\.0000                      ..0656                     ...0656      16.9200" $log | wc -l`
CRIT6=`$GREP  "XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000     ..675553" $log | wc -l`
CRIT7=`$GREP  "                  ...0856                      ..0428                      ..0428     ..732119" $log | wc -l`
CRIT8=`$GREP  "                  ...1312                      ..0656                      ..0656     ..816679" $log | wc -l`
CRIT9=`$GREP  "                  (\-0| \-| 0|  )\.0000                      ..0428                     ...0428     ..682705" $log | wc -l`
CRIT10=`$GREP "                  (\-0| \-| 0|  )\.0000                      ..0656                     ...0656     ..69257." $log | wc -l`
TEST[2]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10`
CTRL[2]=19
ERROR[2]="FREQ.-DEP. CCS FIRST HYPERPOLARIZABILITIES NOT CORRECT"


# freq.-dep. CCSD hyperpolarizabilities
CRIT1=`$GREP  "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000      15.3808" $log | wc -l`
CRIT2=`$GREP  "                  ...0856                      ..0428                      ..0428      15.8480" $log | wc -l`
CRIT3=`$GREP  "                  ...1312                      ..0656                      ..0656      16.5139" $log | wc -l`
CRIT4=`$GREP  "                  (\-0| \-| 0|  )\.0000                      ..0428                     ...0428      15.5341" $log | wc -l`
CRIT5=`$GREP  "                  (\-0| \-| 0|  )\.0000                      ..0656                     ...0656      15.7446" $log | wc -l`
CRIT6=`$GREP  "XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000     ..902738" $log | wc -l`
CRIT7=`$GREP  "                  ...0856                      ..0428                      ..0428     ..990566" $log | wc -l`
CRIT8=`$GREP  "                  ...1312                      ..0656                      ..0656      1.12473" $log | wc -l`
CRIT9=`$GREP  "                  (\-0| \-| 0|  )\.0000                      ..0428                     ...0428     ..914688" $log | wc -l`
CRIT10=`$GREP "                  (\-0| \-| 0|  )\.0000                      ..0656     *     ...0656     ..931267" $log | wc -l`
TEST[3]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10`
CTRL[3]=19
ERROR[3]="FREQ.-DEP. CCSD FIRST HYPERPOLARIZABILITIES NOT CORRECT"



PASSED=1
for i in 1 2 3 
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
